/*
package com.yc.txx.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("email")
public class EmailController {
    @Autowired
    private UserMapper userMapper;
    @Resource
    private JavaMailSender javaMailSender;

    @Autowired
    IUserService userService;

    //读取yml文件中username的值并赋值给form
    @Value("${spring.mail.username}")
    private String from;
    StringBuilder code;
    @RequestMapping("sendEmail")
    public String sendSimpleMail(@RequestParam(value = "emailReceiver") String emailReceiver,@RequestParam("uname")String uname) {
        System.out.println(emailReceiver);
        System.out.println(uname);
        System.out.println("userMapper.selectEmail(uname) = " + userMapper.selectUsersByEname(uname));
        List<User> user =  userMapper.selectUsersByEname(uname);
        String email = user.get(0).getEamil();
        System.out.println(email);
        if(email.equals(emailReceiver)){
            // 构建一个邮件对象
            SimpleMailMessage message = new SimpleMailMessage();

            // 设置邮件发送者
            message.setFrom(from);
            // 设置邮件接收者
            message.setTo(emailReceiver);
            // 设置邮件的主题
            message.setSubject("登录验证码");
            // 设置邮件的正文
            Random random = new Random();
            code = new StringBuilder();
            for (int i = 0; i < 6; i++) {
                int r = random.nextInt(10);
                code.append(r);
            }
            String text = "您的验证码为：" + code + ",请勿泄露给他人。";
            message.setText(text);
            // 发送邮件
            try {
                javaMailSender.send(message);
                return "1";
            } catch (MailException e) {
                e.printStackTrace();
            }
            return "0";
        }else{
            return "0";
        }


    }

    @RequestMapping("code")
    public int code(@RequestParam("yzm") String code1) {
        System.out.println("code"+code);
        System.out.println(code1);
        System.out.println("code1"+ code1);
        if(code.toString().equals(code1)){
            System.out.println("xaingt1");
            return 1;
        }else{
            return 2;
        }

    }

    @RequestMapping("setPwd")
    public Result setPwd(@RequestParam("pwd") String pwd,@RequestParam("uname") String uname) {
        System.out.println(pwd);
        System.out.println(uname);

        int result = userMapper.updateUser(pwd, uname);
        if(result == 1){
            return Result.ok("修改成功",1);
        }else{
            return Result.fail("修改失败",0);
        }

    }
}

*/
